#!/usr/bin/env python
# -*- coding:utf-8 -*-

import random

class Shape(object):
    @classmethod
    def factory(cls,type):
        if type == "Circle":
            return Circle()
        if type == "Square":
            return Square()
        assert 0,"Bad shape creation:"+type

class Circle(Shape):
    def draw(self):
        print ("Circle.draw")
    def erase(self):
        print ("Circle.erase")

class Square(Shape):
    def draw(self): print("Square.draw")
    def erase(self): print("Square.erase")



def shapeNameGen(n):
    print ("*******************")
    types = Shape.__subclasses__()
    print ("****************")
    print (types)
    print (range(n))
    for i in range(n):
        name = random.choice(types).__name__
        print (name)
        yield name

# shapes = []
# for i in shapeNameGen(7):
#     shapes.append(Shape.factory(i))

shapes = [Shape.factory(i) for i in shapeNameGen(7)]

for shape in shapes:
    shape.draw()
    shape.erase()

# if __name__ == "__main__":
#     print ("**************")
#     shapeNameGen(3)


